package com.zhangtai.mq.listener;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.rabbitmq.client.Channel;
import com.zhangtai.Neusoft.service.NeuEmployeeSalaryService;
import com.zhangtai.Neusoft.service.NeusoftEmployeeChangeService;
import com.zhangtai.config.AsyncMethod;
import com.zhangtai.exception.QwMsg;
import com.zhangtai.exception.RException;
import com.zhangtai.exception.SendErr;
import com.zhangtai.modules.constVo.*;
import com.zhangtai.modules.controller.admin.*;
import com.zhangtai.modules.dao.*;
import com.zhangtai.modules.entity.certificate.CertificateEntity;
import com.zhangtai.modules.entity.credential.CredentialHangEntity;
import com.zhangtai.modules.entity.credential.CredentialInfoEntity;
import com.zhangtai.modules.entity.employee.*;
import com.zhangtai.modules.entity.flow.FlowEntity;
import com.zhangtai.modules.entity.leave.DistributeLeaveEntity;
import com.zhangtai.modules.entity.leave.LeaveInfoEntity;
import com.zhangtai.modules.entity.leave.ShiftEntity;
import com.zhangtai.modules.entity.regular.RegularBpmEntity;
import com.zhangtai.modules.entity.salary.*;
import com.zhangtai.modules.entity.transfer.TransferInfoEntity;
import com.zhangtai.modules.jobTask.qw.QwUserEntity;
import com.zhangtai.modules.service.common.NoticeService;
import com.zhangtai.modules.service.credential.CredentialHangService;
import com.zhangtai.modules.service.credential.CredentialInfoService;
import com.zhangtai.modules.service.dimission.DimissionSettlementService;
import com.zhangtai.modules.service.dimission.DimissionUpcomingService;
import com.zhangtai.modules.service.employee.EmployeeBpmService;
import com.zhangtai.modules.service.employee.EmployeeInfoService;
import com.zhangtai.modules.service.employee.EmployeeRecruitmentService;
import com.zhangtai.modules.service.flow.FlowService;
import com.zhangtai.modules.service.leave.DistributeLeaveService;
import com.zhangtai.modules.service.leave.LeaveInfoService;
import com.zhangtai.modules.service.promotion.PromotionService;
import com.zhangtai.modules.service.regular.RegularBpmService;
import com.zhangtai.modules.service.salary.ComputerSubsidyService;
import com.zhangtai.modules.service.salary.SalaryChangeService;
import com.zhangtai.modules.service.salary.SalaryDistributionService;
import com.zhangtai.utils.BeanUtilsMabach;
import com.zhangtai.utils.DateUtils;
import com.zhangtai.utils.SnowflakeIdWorker;
import com.zhangtai.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;

import java.io.IOException;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.util.*;

/**
 * @Author: ming
 * @Date: 2020/6/1 0001 上午 12:22
 */
@Component
@Slf4j
public class Listener {

    @Autowired
    private EmployeeInfoDao employeeInfoDao;
    @Autowired
    private PromotionDao promotionDao;
    @Autowired
    private FlowService flowService;
    @Autowired
    private NoticeService noticeService;
    @Autowired
    private PromotionController promotionController;
    @Autowired
    private DimissionDao dimissionDao;

    @Autowired
    private DimissionInfoDao dimissionInfoDao;
    @Autowired
    private DimissionSettlementService dimissionSettlementService;
    @Autowired
    private TransferController transferController;
    @Autowired
    private TransferInfoDao transferInfoDao;
    @Autowired
    private QwMsg qwMsg;
    @Autowired
    private EmployeeBpmService employeeBpmService;
    @Autowired
    private EmployessController employessController;
    @Autowired
    private NoticeController noticeController;

    @Autowired
    private AwardApplicantDao awardApplicantDao;
    @Autowired
    private AwardPackageDao awardPackageDao;

    @Autowired
    private DimissionSettlementDao dimissionSettlementDao;
    @Autowired
    private DimissionUpcomingService dimissionUpcomingService;

    @Autowired
    private DimissionAuditDao dimissionAuditDao;
    @Autowired
    private SnowflakeIdWorker snowflakeIdWorker;
    @Autowired
    private LeaveInfoService leaveInfoService;
    @Autowired
    private EmployeeInfoService employeeInfoService;
    @Autowired
    private RegularBpmService regularBpmService;
    @Autowired
    private QwUserDao qwUserDao;
    @Autowired
    private SalaryChangeService salaryChangeService;
    @Autowired
    private JobController jobController;

    @Autowired
    private SalaryChangeDao salaryChangeDao;

    @Autowired
    private AsyncMethod asyncMethod;
    @Autowired
    private RegularBpmDao regularBpmDao;
    @Autowired
    private PromotionService promotionService;
    @Autowired
    private SalaryDistributionService salaryDistributionService;
    @Autowired
    private SendErr sendErr;
    @Autowired
    private EmployeeSecondmentDao employeeSecondmentDao;
    @Autowired
    private CertificateDao certificateDao;
    @Autowired
    private EsignController esignController;
    @Autowired
    private NeusoftEmployeeChangeService neusoftEmployeeChangeService;
    @Autowired
    private CredentialHangService credentialHangService;
    @Autowired
    private AwardInfoDao awardInfoDao;
    @Autowired
    private NeuEmployeeSalaryService neuEmployeeSalaryService;
    @Autowired
    private CredentialInfoService credentialInfoService;
    @Autowired
    private ShiftDao shiftDao;
    @Autowired
    private DistributeLeaveService distributeLeaveService;
    @Autowired
    private ComputerSubsidyDao computerSubsidyDao;
    @Autowired
    private ComputerSubsidyService computerSubsidyService;
    @Autowired
    private EmployeeRecruitmentService employeeRecruitmentService;


//    @RabbitListener(queues = "hrsystem.instance.action.type") //生产队列
//    @RabbitListener(queues = "${bpm.listen}") //队列会根据yml环境进行切换
    @Transactional
    public void rabbitMqListener(Channel channel, Message message) {


        String s = new String(message.getBody(), StandardCharsets.UTF_8);
        log.info("监听的消息是:{}", s);
//        如果消息体为空，则签收
        if (StringUtils.isEmpty(s)) {
            try {
                channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
            } catch (IOException e) {
                e.printStackTrace();

            }
        }

//        try {
//            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
//        } catch (IOException e) {
//            e.printStackTrace();
//        }


        try {
            JSONObject object = JSON.parseObject(s);
            String type = object.getString("type");
            String flowId = object.getString("boid"); //流程业务id
            JSONObject data = object.getJSONObject("data");
            JSONObject businessObject = object.getJSONObject("businessObject");

//            String userid = object.getString("userid");
//            ArrayList<String> arrayList = new ArrayList<>();
//            arrayList.add("ZT023748");
//            arrayList.add("ZT023748");

            String status = null;
            String url = null;
            String mobileUrl = null;
            if ("audit".equals(type)) {
                JSONObject auditData = data.getJSONObject("auditData");
                status = auditData.getString("action");
            }
            if ("approveClose".equals(type)) {

                //            log.info("data:{}",data);
                if (!ObjectUtils.isEmpty(data)) {
                    JSONObject approveCloseData = data.getJSONObject("approveCloseData");
                    if (!ObjectUtils.isEmpty(approveCloseData)) {
                        status = approveCloseData.getString("status");

                    }
                }
            }

            if ("createResult".equals(type)) {
                JSONObject createResultData = data.getJSONObject("createResultData");
                url = createResultData.getString("url");
                mobileUrl = createResultData.getString("mobileurl");
                status = createResultData.getString("status");
            }


            log.info("status====>:{}", status);
            //根据流程id查找订单
            FlowEntity flowEntity = flowService.getByIdE(Long.parseLong(flowId));

            log.info("flowEntity:{}", flowEntity);

            //员工录用流程处理
            if (BpmConst.BPM_NEW_EMPLOYEE.equals(flowEntity.getFlowType())) {

                EmployeeInfoEntity employeeInfoEntity = employeeInfoDao.selectOne(new QueryWrapper<EmployeeInfoEntity>().eq("oid", flowEntity.getRelateId()).eq("is_delete", 0));

                log.info("员工录用流程处理====>>>:{}", employeeInfoEntity);
                newEmployee(type, status, employeeInfoEntity, flowEntity, url, s); //flowType=0，则修走新员工录用的逻辑

            }
            //员工调动流程处理
            else if (BpmConst.BPM_TRANSFER.equals(flowEntity.getFlowType())) {
                TransferInfoEntity transferInfoEntity = transferInfoDao.selectOne(new QueryWrapper<TransferInfoEntity>().eq("is_delete", 0).eq("transfer_id", flowEntity.getRelateId()));
                if (!ObjectUtils.isEmpty(transferInfoEntity)) {
                    doTransfer(type, status, transferInfoEntity, flowEntity, url, s);
                }

            }
            //员工晋升流程处理
            else if (BpmConst.BPM_PROMOTION.equals(flowEntity.getFlowType())) {
                PromotionEntity promotionEntity = promotionDao.selectOne(new QueryWrapper<PromotionEntity>().eq("promotion_id", flowEntity.getRelateId()).eq("is_delete", 0));
                if (!ObjectUtils.isEmpty(promotionEntity)) {
                    doPromotion(type, status, promotionEntity, flowEntity, url);
                }

            }
            //员工离职申请流程处理
            else if (BpmConst.BPM_DIMISSION.equals(flowEntity.getFlowType())) {
                DimissionInfoEntity dimissionInfoEntity = dimissionInfoDao.selectOne(new QueryWrapper<DimissionInfoEntity>().eq("id", flowEntity.getRelateId()).eq("is_delete", 0));
                if (!ObjectUtils.isEmpty(dimissionInfoEntity) && 3 != flowEntity.getStatus())
                    dimissionExamine(type, status, dimissionInfoEntity, flowEntity, url);
            }  //员工薪资奖罚
            else if (BpmConst.BPM_AWARD.equals(flowEntity.getFlowType())) {

                AwardApplicantEntity awardApplicantEntity = awardApplicantDao.selectOne(new QueryWrapper<AwardApplicantEntity>().eq("id", flowEntity.getRelateId()).eq("is_delete", 0));
                if (!ObjectUtils.isEmpty(awardApplicantEntity) && 3 != flowEntity.getStatus())
                    updateAwardStatus(type, status, awardApplicantEntity, flowEntity, url);
            }
            //薪资奖罚包
            else if (BpmConst.BPM_AWARD_PACKAGE.equals(flowEntity.getFlowType())) {

                AwardPackageEntity awardPackageEntity = awardPackageDao.selectOne(new QueryWrapper<AwardPackageEntity>().eq("id", flowEntity.getRelateId()).eq("is_delete", 0));
                if (!ObjectUtils.isEmpty(awardPackageEntity) && 3 != flowEntity.getStatus())
                    updateAwardPackageStatus(type, status, awardPackageEntity, flowEntity, url);
            }
            //员工离职结算
            else if (BpmConst.BPM_DIMISSION_SET.equals(flowEntity.getFlowType())) {
                DimissionSettlementEntity dimissionSettlementEntity = dimissionSettlementDao.selectOne(new QueryWrapper<DimissionSettlementEntity>().eq("id", flowEntity.getRelateId()).eq("is_delete", 0));
                if (!ObjectUtils.isEmpty(dimissionSettlementEntity) && 3 != flowEntity.getStatus())
                    dimissionSettlement(type, status, dimissionSettlementEntity, flowEntity, url);
            }
            //员工调班申请
            else if (BpmConst.BPM_SHIFT.equals(flowEntity.getFlowType())) {
                ShiftEntity shiftEntity = shiftDao.selectOne(new QueryWrapper<ShiftEntity>().eq("id", flowEntity.getRelateId()).eq("is_delete", 0));
                if (!ObjectUtils.isEmpty(shiftEntity) && 3 != flowEntity.getStatus())
                    shift(type, status, shiftEntity, flowEntity, url);
            }
            //员工离任审计通知
            else if (BpmConst.BPM_DIMISSION_AUDIT.equals(flowEntity.getFlowType())) {
                DimissionAuditEntity dimissionAuditEntity = dimissionAuditDao.selectOne(new QueryWrapper<DimissionAuditEntity>().eq("id", flowEntity.getRelateId()).eq("is_delete", 0));
                if (!ObjectUtils.isEmpty(dimissionAuditEntity) && 3 != flowEntity.getStatus())
                    dimissionAudit(type, status, dimissionAuditEntity, flowEntity, url);
            }
            //员工借调申请
            else if (BpmConst.BPM_SECONDMENT_APPLY.equals(flowEntity.getFlowType())) {
                EmployeeSecondmentEntity employeeSecondmentEntity = employeeSecondmentDao.selectOne(new QueryWrapper<EmployeeSecondmentEntity>().eq("id", flowEntity.getRelateId()).eq("is_delete", 0));
                if (!ObjectUtils.isEmpty(employeeSecondmentEntity) && 3 != flowEntity.getStatus())
                    setEmployeeSecondment(type, status, employeeSecondmentEntity, flowEntity, url);
            }
            //电脑补贴
            else if (BpmConst.BPM_SUBSIDY.equals(flowEntity.getFlowType())) {
                ComputerSubsidyEntity computerSubsidyEntity = computerSubsidyDao.selectOne(new QueryWrapper<ComputerSubsidyEntity>().eq("id", flowEntity.getRelateId()).eq("is_delete", 0));
                if (!ObjectUtils.isEmpty(computerSubsidyEntity) && 3 != flowEntity.getStatus())
                    ComputerSubsidy(type, status, computerSubsidyEntity, flowEntity, url);
            }


            //请假调休
            else if (BpmConst.BPM_LEAVE.equals(flowEntity.getFlowType())) {
                LeaveInfoEntity leaveInfoEntity = leaveInfoService.getByIdE(flowEntity.getRelateId());
                if (!ObjectUtils.isEmpty(leaveInfoEntity)) {
                    updateLeaveStatus(type, status, leaveInfoEntity, flowEntity, url, mobileUrl);
                }
            }
//            新员工转正
            else if (BpmConst.BPM_REGUALR.equals(flowEntity.getFlowType())) {


                log.info("开始处理新员工转正流程==============》》》》》》》》》》》");
                newEmployeeRegular(type, status, flowEntity, url, businessObject, s);

            }

            //薪资变动
            else if (BpmConst.BPM_FIXED_SALARY.equals(flowEntity.getFlowType())) {

                log.info("开始处理薪资变动==============》》》》》》》》》》》");
                SalaryChangeEntity salaryChangeEntity = salaryChangeDao.selectOne(new QueryWrapper<SalaryChangeEntity>().eq("id", flowEntity.getRelateId()).eq("is_delete", 0));
                if (!ObjectUtils.isEmpty(salaryChangeEntity) && 3 != flowEntity.getStatus())
                    SalaryChange(type, status, salaryChangeEntity, flowEntity, url, s);
            }
//            管理晋级转正
            else if (BpmConst.MANAGEMENT_BPM_REGUALR.equals(flowEntity.getFlowType())) {
                log.info("开始处理管理转正==============》》》》》》》》》》》");
                ManagementRegular(type, status, flowEntity, url, s);
            }
            //员工开具证明
            else if (BpmConst.BPM_CERTIFICATE.equals(flowEntity.getFlowType())) {
                CertificateEntity certificateEntity = certificateDao.selectOne(new QueryWrapper<CertificateEntity>().eq("id", flowEntity.getRelateId()).eq("is_delete", 0));
                if (!ObjectUtils.isEmpty(certificateEntity))
                    updateCertificateStatus(type, status, certificateEntity, flowEntity, url, s);
            }
            //资质挂证
            else if (BpmConst.BPM_CREDENTIAL.equals(flowEntity.getFlowType())) {
                CredentialHangEntity credentialHangEntity = credentialHangService.getByIdE(flowEntity.getRelateId());
                if (!ObjectUtils.isEmpty(credentialHangEntity))
                    updateCredentialStatus(type, status, credentialHangEntity, url, s, flowEntity);
            }
            //零星调休
            else if (BpmConst.BPM_DISTRIBUTE_LEAVE.equals(flowEntity.getFlowType())) {
                DistributeLeaveEntity entity = distributeLeaveService.getByIdE(flowEntity.getRelateId());
                if (!ObjectUtils.isEmpty(entity))
                    updateDistributeLeaveStatus(type, status, entity, url, s, flowEntity);
            }

        } catch (Exception e) {
            e.printStackTrace();
            log.error("mq消费者报错\n" + Arrays.asList(e.getStackTrace()));
            log.error("请求报文是：{}", s);
            String time = DateUtils.format(new Date(), DateUtils.DATE_TIME_PATTERN);
            ArrayList<StackTraceElement> stackTraceElements = new ArrayList<>();
            for (StackTraceElement stackTraceElement : e.getStackTrace()) {
                if (stackTraceElement.toString().contains("com.zhangtai")) {
                    stackTraceElements.add(stackTraceElement);
                }
            }
            sendErr.sendMsg(time + ",mq消费者报错:" + e + "\n" + stackTraceElements);


            throw new RException("mq消费者报错", e);
        }


        /* 执行成功手动ack
            message.getMessageProperties().getDeliveryTag()  是消息的唯一标识
            false  不开启批量处理
             */


        try {
            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
        } catch (IOException e) {
            e.printStackTrace();

        }
        log.info("流程被签收了222222");

    }

    /**
     * 新员工录用流程
     *
     * @param type
     * @param status
     * @param employeeInfoEntity
     */
    @Transactional
    public void newEmployee(String type, String status, EmployeeInfoEntity employeeInfoEntity, FlowEntity flowEntity, String url, String s) {
        String content = "";

        EmployeeBpmEntity bpmEntity = employeeBpmService.getByIdE(employeeInfoEntity.getOid());
        String offContent = "您有一位员工Offer待发送：" + bpmEntity.getName();
        Integer j = 1;
//        log.info("type==========>>{}",type);
        //        审核通过 type为：approveClose ,status为：approved
        if ("createResult".equals(type) && "success".equals(status)) {
            bpmEntity.setCheckUrl(url);
            employeeInfoEntity.setCheckUrl(url);
            if (employeeInfoEntity.getStatus() != 0 || employeeInfoEntity.getStatus() != 1){
                employeeInfoEntity.setStatus(2);}
            employeeInfoDao.updateById(employeeInfoEntity);
            //更新录用待办通知为已处理状态
            noticeController.updateNoticeTodo(employeeInfoEntity.getOid(), NoticeConst.TODO_TYPE_HIRE);
        }
        log.info("员工录用流程：type:{},status:{}", type, status);
        if ("approveClose".equals(type) && "approved".equals(status)) {
            //审核通过则修改订单状态IsVerify为3
            if (!ObjectUtils.isEmpty(employeeInfoEntity)) {
                log.info("录用审核通过，修改状态为3");
                employeeInfoEntity.setStatus(3);
                employeeInfoDao.updateById(employeeInfoEntity);
                flowEntity.setStatus(3);
                flowService.updateByIdE(flowEntity);
                content = employeeInfoEntity.getName() + "的录用申请流程已审批已经通过";
                //审核通过发送入职待办
                employessController.sendHireToDo(employeeInfoEntity);
                //更新录用待办通知为已处理状态
                noticeController.updateNoticeTodo(employeeInfoEntity.getOid(), NoticeConst.TODO_TYPE_HIRE);
                //生成薪资变动
                asyncMethod.saveSalaryChange(s, flowEntity, null, employeeInfoEntity.getCheckUrl());
            }
        }
        if ("approveClose".equals(type) && "canceled".equals(status)) {
            //驳回后的执行逻辑 4:流程作废
            log.info("流程作废了");
            //作废将该条信息置为未发起
            employeeInfoEntity.setStatus(0);
            employeeInfoDao.updateById(employeeInfoEntity);
            flowEntity.setStatus(4);
            flowService.updateByIdE(flowEntity);
            content = employeeInfoEntity.getName() + "的录用申请流程审批已作废，请重新发起";
        }


        //修改招聘录用状态
        if(!org.springframework.util.StringUtils.isEmpty(employeeInfoEntity.getRecruitmentId())){
            EmployeeRecruitmentEntity employeeRecruitmentEntity=  new EmployeeRecruitmentEntity();
            employeeRecruitmentEntity.setId(employeeInfoEntity.getRecruitmentId());
            employeeRecruitmentEntity.setCheckUrl(url);
            employeeRecruitmentEntity.setStatus(employeeInfoEntity.getStatus());
            employeeRecruitmentService.updateByIdE(employeeRecruitmentEntity);
        }

        if (!StringUtils.isEmpty(content) && !j.equals(bpmEntity.getIsRemind()) && "approveClose".equals(type)) {
            qwMsg.sendNoticeMsg("录用", content, NoticeConst.MSG_TYPE_NEW_EMPLOYEE, true, employeeInfoEntity.getOid(), flowEntity.getRelateId(), "录用", bpmEntity.getApplyUserCode(), null, null);
            if ("approved".equals(status)) {
                qwMsg.sendNoticeMsg("Offer发送", offContent, NoticeConst.TODO_TYPE_OFFER_SEND, false, employeeInfoEntity.getOid(), flowEntity.getRelateId(), "offer", null, new Date(), employeeInfoEntity.getOrgId());
                bpmEntity.setIsRemind(1);
            }
        }
        employeeBpmService.updateByIdE(bpmEntity);
    }

    /**
     * 离职申请审核流程
     *
     * @param type
     * @param status
     * @param dimissionInfoEntity
     * @param flowEntity
     */
    @Transactional
    public void dimissionExamine(String type, String status, DimissionInfoEntity dimissionInfoEntity, FlowEntity flowEntity, String url) {
        //String content = "";
        //EmployeeInfoEntity employeeInfoEntity = employeeInfoDao.selectOne(new QueryWrapper<EmployeeInfoEntity>().eq("oid", dimissionInfoEntity.getId()));
        //审核通过 type为：approveClose ,status为：approved
        log.info("type==========>>{}", type);


        if ("createResult".equals(type) && "success".equals(status)) {
            dimissionInfoEntity.setBpmDetailUrl(url);
            dimissionInfoEntity.setRurnoverStatus(1);
        }

        //        审核通过 type为：approveClose ,status为：approved
        if ("approveClose".equals(type) && "approved".equals(status)) {

            log.info("离职申请通过，修改状态为2");
            dimissionInfoEntity.setRurnoverStatus(2);
            DimissionSettlementEntity dimissionSettlementEntity = new DimissionSettlementEntity();
            long id = snowflakeIdWorker.nextId();
            dimissionSettlementEntity.setId(id);
            dimissionSettlementEntity.setIsDelete(0);
            dimissionSettlementEntity.setStatus(0);
            //dimissionSettlementEntity.setSptype(8);
            dimissionSettlementEntity.setCreateTime(new Date());
            dimissionSettlementEntity.setDimissionId(dimissionInfoEntity.getId());
            String applyCode = dimissionInfoEntity.getApplyCode();
            dimissionSettlementService.saveE(dimissionSettlementEntity);
            flowEntity.setStatus(3);
            flowService.updateByIdE(flowEntity);
            //  employeeInfoEntity.setEmployeestatus("6");
            ///  employeeInfoDao.updateById(employeeInfoEntity);
            //  content = employeeInfoEntity.getName() + "的离职申请流程已审批已经通过";
        }
        if ("approveClose".equals(type) && "canceled".equals(status)) {
            //驳回后的执行逻辑 2:流程作废
            log.info("流程作废了");
            dimissionInfoEntity.setRurnoverStatus(0);
            flowEntity.setStatus(4);
            flowService.updateByIdE(flowEntity);
            // content = employeeInfoEntity.getName() + "的离职申请流程已作废，请重新发起";
        }
        //更新离职表
        dimissionInfoDao.updateById(dimissionInfoEntity);

        //发送消息给HR
        /*  if(!StringUtils.isEmpty(content)&&!j.equals(dimissionEntity.getIsRemind())){
              qwMsg.sendNoticeMsg("离职",content, NoticeConst.MSG_TYPE_DIMISSION,true,employeeInfoEntity.getOid(),flowEntity.getRelateId(),"离职",dimissionEntity.getApply_code(),null,null);
              dimissionEntity.setIsRemind(1);
          }*/


    }

    /**
     * 调班申请审核流程
     *
     * @param type
     * @param status
     * @param shiftEntity
     * @param flowEntity
     */
    @Transactional
    public void shift(String type, String status, ShiftEntity shiftEntity, FlowEntity flowEntity, String url) {
        log.info("type==========>>{}", type);
        //        审核通过 type为：approveClose ,status为：approved
        if ("createResult".equals(type) && "success".equals(status)) {
            shiftEntity.setBpmUrl(url);
            shiftEntity.setApproveStatus(1);
        }
        if ("approveClose".equals(type) && "approved".equals(status)) {
            log.info("职结算审核通过，修改状态为2");
            shiftEntity.setApproveStatus(2);
            flowEntity.setStatus(3);
            flowService.updateByIdE(flowEntity);
        }
        if ("approveClose".equals(type) && "canceled".equals(status)) {
            //驳回后的执行逻辑 2:流程作废
            log.info("流程作废了");
            shiftEntity.setApproveStatus(0);
            flowEntity.setStatus(4);
            flowService.updateByIdE(flowEntity);
        }
        //更新离职结算表
        shiftDao.updateById(shiftEntity);
    }


    /**
     * 离职结算审核流程
     *
     * @param type
     * @param status
     * @param dimissionSettlementEntity
     * @param flowEntity
     */
    @Transactional
    public void dimissionSettlement(String type, String status, DimissionSettlementEntity dimissionSettlementEntity, FlowEntity flowEntity, String url) {
        log.info("type==========>>{}", type);
        //        审核通过 type为：approveClose ,status为：approved
        if ("createResult".equals(type) && "success".equals(status)) {
            dimissionSettlementEntity.setBpmDetailUrl(url);
            dimissionSettlementEntity.setStatus(1);
        }
        if ("approveClose".equals(type) && "approved".equals(status)) {
            log.info("职结算审核通过，修改状态为2");
            dimissionSettlementEntity.setStatus(2);
            dimissionSettlementEntity.setProcessingStatus(1);
            flowEntity.setStatus(3);
            flowService.updateByIdE(flowEntity);
        }
        if ("approveClose".equals(type) && "canceled".equals(status)) {
            //驳回后的执行逻辑 2:流程作废
            log.info("流程作废了");
            dimissionSettlementEntity.setStatus(0);
            flowEntity.setStatus(4);
            flowService.updateByIdE(flowEntity);
        }
        //更新离职结算表
        dimissionSettlementDao.updateById(dimissionSettlementEntity);
    }


    /**
     * 离任审计通知审核流程
     *
     * @param type
     * @param status
     * @param dimissionAuditEntity
     * @param flowEntity
     */
    @Transactional
    public void dimissionAudit(String type, String status, DimissionAuditEntity dimissionAuditEntity, FlowEntity flowEntity, String url) {
        log.info("type==========>>{}", type);
        //        审核通过 type为：approveClose ,status为：approved
        if ("createResult".equals(type) && "success".equals(status)) {
            dimissionAuditEntity.setBpmDetailUrl(url);
            dimissionAuditEntity.setStatus(1);
        }
        if ("approveClose".equals(type) && "approved".equals(status)) {
            log.info("离任审计通知审核通过，修改状态为2");
            dimissionAuditEntity.setStatus(2);
            dimissionAuditEntity.setEndTime(new Date());
            DimissionUpcomingEntity dimissionUpcomingEntity = new DimissionUpcomingEntity();
            long id = snowflakeIdWorker.nextId();
            dimissionUpcomingEntity.setId(id);
            dimissionUpcomingEntity.setIsDelete(0);
            dimissionUpcomingEntity.setAuditId(dimissionAuditEntity.getId());
            dimissionUpcomingEntity.setCreateTime(new Date());
            dimissionUpcomingEntity.setStatus(0);
            dimissionUpcomingService.saveE(dimissionUpcomingEntity);
            flowEntity.setStatus(3);
            flowService.updateByIdE(flowEntity);
        }
        if ("approveClose".equals(type) && "canceled".equals(status)) {
            //驳回后的执行逻辑 2:流程作废
            log.info("流程作废了");
            dimissionAuditEntity.setStatus(0);
            dimissionAuditEntity.setEndTime(new Date());
            flowEntity.setStatus(4);
            flowService.updateByIdE(flowEntity);
        }
        //更新离职结算表
        dimissionAuditDao.updateById(dimissionAuditEntity);
        //发送消息给HR
        /*  if(!StringUtils.isEmpty(content)&&!j.equals(dimissionEntity.getIsRemind())){
              qwMsg.sendNoticeMsg("离职",content, NoticeConst.MSG_TYPE_DIMISSION,true,employeeInfoEntity.getOid(),flowEntity.getRelateId(),"离职",dimissionEntity.getApply_code(),null,null);
              dimissionEntity.setIsRemind(1);
          }*/
    }


    /**
     * 员工借调申请审核流程
     */
    @Transactional
    public void setEmployeeSecondment(String type, String status, EmployeeSecondmentEntity employeeSecondmentEntity, FlowEntity flowEntity, String url) {
        log.info("type==========>>{}", type);
        //        审核通过 type为：approveClose ,status为：approved
        if ("createResult".equals(type) && "success".equals(status)) {
            employeeSecondmentEntity.setBpmUrl(url);
            employeeSecondmentEntity.setStatus(1);
        }
        if ("approveClose".equals(type) && "approved".equals(status)) {
            log.info("员工借调申请审核通过，修改状态为2");
            employeeSecondmentEntity.setStatus(2);
            flowEntity.setStatus(3);
            flowService.updateByIdE(flowEntity);
            computerSubsidyService.saveComputerSubsidy(
                    employeeSecondmentEntity.getOutTime(),
                    employeeSecondmentEntity.getOid(),
                    employeeSecondmentEntity.getBeforeSubsidyEnd(),
                    employeeSecondmentEntity.getBeforeSubsidyId(),
                    employeeSecondmentEntity.getAfterSubsidy(),
                    employeeSecondmentEntity.getAfterSubsidyStart(),
                    employeeSecondmentEntity.getAfterSubsidyEnd(),
                    employeeSecondmentEntity.getFileUrl(),
                    employeeSecondmentEntity.getBpmUrl(),
                    employeeSecondmentEntity.getReason());
//
//            EmployeeInfoEntity employeeInfoEntity = employeeInfoDao.selectOne(new QueryWrapper<EmployeeInfoEntity>()
//                    .eq("oid", flowEntity.getOid()).eq("is_delete",0));
//
//            SalaryChangeEntity  salaryChangeEntity=new SalaryChangeEntity();
//            salaryChangeEntity.setApproveStatus(2);
//            salaryChangeEntity.setApplyTime(employeeSecondmentEntity.getOutTime());
//            salaryChangeEntity.setCreateTime(new Date());
//            salaryChangeEntity.setIsDelete(0);
//            salaryChangeEntity.setStatus(0);
////            salaryChangeEntity.setOrgId(employeeInfoEntity.getOrgId());
//            salaryChangeEntity.setUnitId(employeeInfoEntity.getUnitId());
//            salaryChangeEntity.setNewJobId(employeeInfoEntity.getJobId());
//            salaryChangeEntity.setNewOrgId(employeeInfoEntity.getOrgId());
//            salaryChangeEntity.setNewUnitId(employeeInfoEntity.getUnitId());
//            salaryChangeEntity.setNewJobLevel(employeeInfoEntity.getJobLevel());
//            salaryChangeEntity.setNewJobLevelId(employeeInfoEntity.getJobLevelId());
//            salaryChangeEntity.setNewJobLevelType(employeeInfoEntity.getJobLevelType());
//
//            salaryChangeEntity.setOid(flowEntity.getOid());
//            salaryChangeEntity.setType(SalaryConst.SALARY_TYPE_SECONDMENT);
//            salaryChangeEntity.setEffectiveTime(employeeSecondmentEntity.getOutTime());
////            //暂时先这样拿
////            salaryChangeEntity.setStandardMonthlySalary(standardMonthlySalary);
////            salaryChangeEntity.setBaseSalary(baseSalary);
////            salaryChangeEntity.setModuleSalaryBase(moduleSalaryBase);
//
//            salaryChangeEntity.setApplyAdjustmentMonthlySalary(new BigDecimal(0));
//            salaryChangeEntity.setApplyBaseSalary(new BigDecimal(0));
//            salaryChangeEntity.setApplyModuleSalaryBase(new BigDecimal(0));
//            salaryChangeEntity.setOriginalAllowanceSubsidy(new BigDecimal(0));
//            salaryChangeEntity.setProposedAdjustmentAllowance(employeeSecondmentEntity.getSubsidy());
//            salaryChangeEntity.setBpmUrl(url);
//            salaryChangeService.saveE(salaryChangeEntity);
//
//            sendSalaryConfirmTodo("您有一位员工薪资审批待确认生效："+employeeInfoEntity.getName(),employeeInfoEntity.getOid(),salaryChangeEntity.getId(),employeeInfoEntity.getOrgId());


            //调用东软借调接口
            //neusoftEmployeeChangeService.uploadSecondment(employeeSecondmentEntity);
        }
        if ("approveClose".equals(type) && "canceled".equals(status)) {
            //驳回后的执行逻辑 2:流程作废
            log.info("流程作废了");
            employeeSecondmentEntity.setStatus(0);
            flowEntity.setStatus(4);
            flowService.updateByIdE(flowEntity);
        }
        //更新员工借调申请
        employeeSecondmentDao.updateById(employeeSecondmentEntity);
        //发送消息给HR
        /*  if(!StringUtils.isEmpty(content)&&!j.equals(dimissionEntity.getIsRemind())){
              qwMsg.sendNoticeMsg("离职",content, NoticeConst.MSG_TYPE_DIMISSION,true,employeeInfoEntity.getOid(),flowEntity.getRelateId(),"离职",dimissionEntity.getApply_code(),null,null);
              dimissionEntity.setIsRemind(1);
          }*/
    }

    private void sendSalaryConfirmTodo(String salaryContent, Long oid, Long relateId, Long orgId) {
        qwMsg.sendNoticeMsg("薪资确认", salaryContent, NoticeConst.TODO_TYPE_SALARY_CONFIRM, false, oid, relateId, "薪资确认", null, new Date(), orgId);
    }

    /**
     * 电脑补贴
     *
     * @param type
     * @param status
     * @param computerSubsidyEntity
     * @param flowEntity
     */
    @Transactional
    public void ComputerSubsidy(String type, String status, ComputerSubsidyEntity computerSubsidyEntity, FlowEntity flowEntity, String url) {
        log.info("type==========>>{}", type);
        //        审核通过 type为：approveClose ,status为：approved
        if ("createResult".equals(type) && "success".equals(status)) {
            computerSubsidyEntity.setBpmUrl(url);
            computerSubsidyEntity.setApproveStatus(1);
        }
        if ("approveClose".equals(type) && "approved".equals(status)) {
            computerSubsidyEntity.setApproveStatus(2);
            computerSubsidyEntity.setStatus(1);
            //设置原生效补贴为已失效
           List<ComputerSubsidyEntity> computerSubsidyEntityList=  computerSubsidyDao.selectList(
                   new QueryWrapper<ComputerSubsidyEntity>()
                           .eq("type",computerSubsidyEntity.getType())
                           .eq("status",1)
                           .ne("id",computerSubsidyEntity.getId()));
           if(!CollectionUtils.isEmpty(computerSubsidyEntityList)){
              for (ComputerSubsidyEntity entity:computerSubsidyEntityList){
                  entity.setStatus(2);
                  computerSubsidyService.updateByIdE(entity);
              }
           }

            flowEntity.setStatus(3);
            flowService.updateByIdE(flowEntity);
        }
        if ("approveClose".equals(type) && "canceled".equals(status)) {
            //驳回后的执行逻辑 2:流程作废
            log.info("流程作废了");
            computerSubsidyEntity.setApproveStatus(0);
            flowEntity.setStatus(4);
            flowService.updateByIdE(flowEntity);
        }
        //更新电脑补贴表
        computerSubsidyDao.updateById(computerSubsidyEntity);
    }

    /**
     * 薪资变动
     *
     * @param type
     * @param status
     * @param salaryChangeEntity
     * @param flowEntity
     */
    @Transactional
    public void SalaryChange(String type, String status, SalaryChangeEntity salaryChangeEntity, FlowEntity flowEntity, String url, String s) {
        log.info("type==========>>{}", type);
        //        审核通过 type为：approveClose ,status为：approved
        if ("createResult".equals(type) && "success".equals(status)) {
            salaryChangeEntity.setBpmUrl(url);
            salaryChangeEntity.setApproveStatus(1);
        }
        if ("approveClose".equals(type) && "approved".equals(status)) {
            log.info("薪资变动审核通过，修改状态为2");
            salaryChangeEntity.setApproveStatus(2);
            DimissionUpcomingEntity dimissionUpcomingEntity = new DimissionUpcomingEntity();
            //生成薪资变动
            asyncMethod.saveSalaryChange(s, flowEntity, salaryChangeEntity, null);
            flowEntity.setStatus(3);
            flowService.updateByIdE(flowEntity);
        }
        if ("approveClose".equals(type) && "canceled".equals(status)) {
            //驳回后的执行逻辑 2:流程作废
            log.info("流程作废了");
            salaryChangeEntity.setApproveStatus(0);
            flowEntity.setStatus(4);
            flowService.updateByIdE(flowEntity);
        }
        //更新薪资变动表
        salaryChangeDao.updateById(salaryChangeEntity);
    }

    /**
     * 员工调动流程
     *
     * @param type
     * @param status
     * @param transferInfoEntity
     * @param flowEntity
     */
    public void doTransfer(String type, String status, TransferInfoEntity transferInfoEntity,
                           FlowEntity flowEntity, String url, String s) {
        EmployeeInfoEntity employeeInfoEntity = employeeInfoDao.selectOne(new QueryWrapper<EmployeeInfoEntity>().eq("oid", transferInfoEntity.getOid()).eq("is_delete", 0));
        EmployeeBpmEntity employeeBpmEntity = employeeBpmService.getByIdE(transferInfoEntity.getOid());
        if (ObjectUtils.isEmpty(employeeBpmEntity)) {
            employeeBpmEntity = BeanUtilsMabach.doToDto(employeeInfoEntity, EmployeeBpmEntity.class);
            employeeBpmService.saveE(employeeBpmEntity);
        }
        String content = "";

        Integer j = 1;
        log.info("type==========>>{}", type);
        //        审核通过 type为：approveClose ,status为：approved
        if ("createResult".equals(type) && "success".equals(status)) {
            if (transferInfoEntity.getAuditStatus() == 0)
                transferInfoEntity.setAuditStatus(1);
            transferInfoEntity.setCheckUrl(url);
        }

        //        审核通过 type为：approveClose ,status为：approved
        if ("approveClose".equals(type) && "approved".equals(status)) {
            log.info("审核通过，修改状态为2");
            transferInfoEntity.setAuditStatus(2);
            transferInfoDao.updateById(transferInfoEntity);
            flowEntity.setStatus(3);
            flowService.updateByIdE(flowEntity);
            content = employeeInfoEntity.getName() + "的调动申请流程已审批已经通过";
            JSONObject obj = JSON.parseObject(s, JSONObject.class);
            JSONObject data = obj.getJSONObject("data");
            JSONObject businessObject = data.getJSONObject("businessObject");
            JSONArray fields = businessObject.getJSONArray("fields");
            BigDecimal salary = new BigDecimal(0);
            BigDecimal base = new BigDecimal(0);
            BigDecimal moudle = new BigDecimal(0);
            for (Object field : fields) {
                JSONObject object = JSON.parseObject(field.toString(), JSONObject.class);
                String id = object.getString("id");
//                String v = "";
//                if(!StringUtils.isEmpty(object.getString("value"))){
//                    v  = object.getString("value").replace("元","");
//                }
                if ("afterSalary".equals(id)) {
                    String v = object.getString("value");
                    if (!StringUtils.isEmpty(v)) {
                        BigDecimal value = new BigDecimal(v);
                        salary = value;
                    } else {
                        salary = new BigDecimal(0);
                    }
                } else if ("afterBase".equals(id)) {
                    String v = object.getString("value");

                    if (!StringUtils.isEmpty(v)) {
                        BigDecimal value = new BigDecimal(v);
                        base = value;
                    } else {
                        base = new BigDecimal(0);
                    }
                } else if ("applyModule".equals(id)) {
                    String v = object.getString("value");

                    if (!StringUtils.isEmpty(v)) {
                        BigDecimal value = new BigDecimal(v);
                        moudle = value;
                    } else {
                        moudle = new BigDecimal(0);
                    }
                }
            }
            //                更新工资 只有大于0才更新

            Integer i = base.compareTo(new BigDecimal(0)); //基础工资
            Integer l = moudle.compareTo(new BigDecimal(0)); //模块工资
            BigDecimal add = salary.add(moudle); //总工资
            int k = add.compareTo(new BigDecimal(0));//总工资
            if (i > 0) {
                employeeInfoEntity.setBasicSalary(base);
                employeeBpmEntity.setBasicSalary(base);
            }

            if (l > 0) {
                employeeInfoEntity.setPerformance(moudle);
                employeeBpmEntity.setPerformance(moudle);
            }


            if (k > 0) {
                employeeInfoEntity.setMonthlySalary(add);
                employeeBpmEntity.setMonthlySalary(add);
            }

            //更新调动后的主表信息
            employeeInfoEntity.setOrgId(transferInfoEntity.getAfterOrgId());
            employeeInfoEntity.setOrgname(transferInfoEntity.getAfterOrg());
            employeeInfoEntity.setUnitId(transferInfoEntity.getAfterDepartmentId());
            employeeInfoEntity.setUnitname(transferInfoEntity.getAfterDepartment());
            employeeInfoEntity.setJobId(transferInfoEntity.getAfterJobId());
            employeeInfoEntity.setJobname(transferInfoEntity.getAfterJob());
            employeeInfoEntity.setJobLevel(transferInfoEntity.getAfterJobLevel());
            employeeInfoEntity.setJobLevelId(transferInfoEntity.getAfterJobLevelId());
            employeeInfoEntity.setJobSystemId(transferInfoEntity.getAfterSystemId());

            employeeBpmService.updateByIdE(employeeBpmEntity);
            employeeInfoService.updateByIdE(employeeInfoEntity);
            //bpm审批通过 更新个人信息到员工信息
           // transferController.transferToEmployee(transferInfoEntity, salary, base);
            if (transferInfoEntity.getTransferType().equals(4)) {
                RegularBpmEntity bpmEntity = new RegularBpmEntity();
                bpmEntity.setCreateTime(new Date());
                bpmEntity.setHiredate(transferInfoEntity.getBeginTransferDate());
                bpmEntity.setOid(transferInfoEntity.getOid());
                bpmEntity.setCode(employeeInfoEntity.getCode());
                bpmEntity.setName(employeeInfoEntity.getName());
                bpmEntity.setJobId(transferInfoEntity.getAfterJobId());
                bpmEntity.setJobLevel(jobController.jobLevelMap.get(transferInfoEntity.getAfterJobLevelId()));
                bpmEntity.setJobLevelId(transferInfoEntity.getAfterJobLevelId());
                bpmEntity.setJobLevelType(transferInfoEntity.getAfterJobLevelType());
                bpmEntity.setJobname(jobController.jobMap.get(transferInfoEntity.getAfterJobId()));
                bpmEntity.setOrgId(transferInfoEntity.getAfterOrgId());
                bpmEntity.setOrgname(jobController.orgMap.get(transferInfoEntity.getAfterOrgId()));
//                Integer months = DateUtils.monthsBetween(transferInfoEntity.getBeginTransferDate(),transferInfoEntity.getEndTransferDate());
                bpmEntity.setProbationday(3);
                bpmEntity.setRegularDay(DateUtils.addDateMonths(transferInfoEntity.getBeginTransferDate(), 3));
                bpmEntity.setRegularType(3);//3:调动管理晋级转正
                bpmEntity.setRelationId(transferInfoEntity.getTransferId());
                bpmEntity.setUnitId(transferInfoEntity.getAfterDepartmentId());
                bpmEntity.setUseraccount(employeeInfoEntity.getUseraccount());
                bpmEntity.setBeforeJobId(employeeInfoEntity.getJobId());
                bpmEntity.setBeforeJobLevel(jobController.jobLevelMap.get(employeeInfoEntity.getJobLevelId()));
                bpmEntity.setUnitname(jobController.orgMap.get(transferInfoEntity.getAfterDepartmentId()));
                bpmEntity.setApplyTime(transferInfoEntity.getBeginTransferDate());
                bpmEntity.setBeforeJobLevelId(employeeInfoEntity.getJobLevelId());
                bpmEntity.setBeforeJobName(jobController.jobMap.get(employeeInfoEntity.getJobId()));
                bpmEntity.setBeforeOrgId(employeeInfoEntity.getOrgId());
                bpmEntity.setBeforeUnitId(employeeInfoEntity.getUnitId());
                bpmEntity.setBeforeUnitName(jobController.orgMap.get(employeeInfoEntity.getUnitId()));
                bpmEntity.setBeforeLevelType(employeeInfoEntity.getJobType());
                bpmEntity.setBeforeOrgName(jobController.orgMap.get(employeeInfoEntity.getOrgId()));
//                只有薪资大于0才更新
                if (i > 0) {
                    bpmEntity.setBasicSalary(base);
                }
                if (l > 0) {
                    bpmEntity.setPerformance(moudle);
                }
                if (k > 0) {
                    bpmEntity.setMonthlySalary(add);
                }
                bpmEntity.setId(snowflakeIdWorker.nextId());
                regularBpmService.saveE(bpmEntity);
            }
            //降级、专业晋升会有薪资变动
            else if (transferInfoEntity.getTransferType().equals(3) || transferInfoEntity.getTransferType().equals(2)) {
                //薪资变动
                asyncMethod.saveSalaryChange(s, flowEntity, null, transferInfoEntity.getCheckUrl());
            }
            //调动都要调整薪资组
            SalaryDistributionEntity salaryDistributionEntity = salaryDistributionService.saveSalaryDistribution(employeeInfoEntity, SalaryConst.SALARY_TYPE_PROFESSION);
            String salaryContent = "您有一位待分配薪资和发薪单位员工：" + employeeInfoEntity.getName();
            qwMsg.sendNoticeMsg("薪资分配", salaryContent, NoticeConst.TODO_TYPE_SALARY_ALLOT, false, employeeInfoEntity.getOid(), salaryDistributionEntity.getId(), "薪资分配", null, new Date(), employeeInfoEntity.getOrgId());
            //如果补贴信息不为空，添加补贴信息
            if (!ObjectUtils.isEmpty(transferInfoEntity.getAfterSubsidy())) {
                computerSubsidyService.saveComputerSubsidy(transferInfoEntity.getBeginTransferDate(), transferInfoEntity.getOid(),
                        transferInfoEntity.getBeforeSubsidyEnd(), transferInfoEntity.getBeforeSubsidyId(), transferInfoEntity.getAfterSubsidy(),
                        transferInfoEntity.getAfterSubsidyStart(), transferInfoEntity.getAfterSubsidyEnd(), transferInfoEntity.getFileUrl(),
                        transferInfoEntity.getCheckUrl(), transferInfoEntity.getReason());
            }
        } else if ("approveClose".equals(type) && "canceled".equals(status)) {
            //驳回后的执行逻辑 4:流程作废
            log.info("流程作废了");
            if (!transferInfoEntity.getAuditStatus().equals(2))
                transferInfoEntity.setAuditStatus(0);
            flowEntity.setStatus(4);
            flowService.updateByIdE(flowEntity);
            content = employeeInfoEntity.getName() + "的调动申请流程已作废，请重新发起";
        }
        //发送消息给HR
        if (!StringUtils.isEmpty(content) && !j.equals(transferInfoEntity.getIsRemind())) {
            qwMsg.sendNoticeMsg("调动", content, NoticeConst.MSG_TYPE_TRANSFER, true, employeeInfoEntity.getOid(), flowEntity.getRelateId(), "调动", transferInfoEntity.getApplyCode(), null, null);
            if ("approved".equals(status)) {
                transferInfoEntity.setIsRemind(1);
            }
        }
        transferInfoDao.updateById(transferInfoEntity);
    }

    @Transactional
    public void doPromotion(String type, String status, PromotionEntity promotionEntity, FlowEntity flowEntity, String url) {
        //        审核通过 type为：approveClose ,status为：approved
        promotionEntity.setPromotionId(flowEntity.getRelateId());
        String content = "";
        Integer j = 1;
        log.info("type==========>>{}", type);
//        int i=1/0;
        //        审核通过 type为：approveClose ,status为：approved
        if ("createResult".equals(type) && "success".equals(status)) {
            if (promotionEntity.getStatus() == 1)
                promotionEntity.setStatus(2);
            promotionEntity.setCheckUrl(url);
        }

        if ("approveClose".equals(type) && "approved".equals(status)) {

            //审核通过则修改订单状态IsVerify为3
            if (!ObjectUtils.isEmpty(promotionEntity)) {
                EmployeeInfoEntity employeeInfoEntity = employeeInfoService.getByIdE(promotionEntity.getOid());
                log.info("审核通过，修改状态为3");
//                promotionEntity.setStatus(3);
//                promotionDao.updateById(promotionEntity);
                flowEntity.setStatus(3);
                //更新员工信息
                promotionController.doPromotionOk(promotionEntity, true);
                //专业晋升插入薪资新变动信息
                if (promotionEntity.getPromotionType().equals(1)) {
                    SalaryChangeEntity salaryChangeEntity = new SalaryChangeEntity();
                    salaryChangeEntity.setOid(promotionEntity.getOid());
                    //薪资变动
                    salaryChangeEntity.setType(SalaryConst.SALARY_TYPE_ENTRY);
                    salaryChangeEntity.setUnitId(promotionEntity.getAfterUnitId());
                    salaryChangeEntity.setEffectiveTime(promotionEntity.getPromotionDate());
                    salaryChangeService.saveE(salaryChangeEntity);
                }
                content = promotionEntity.getName() + "的晋升申请流程已审批已经通过";

            }
        }

        if ("approveClose".equals(type) && "canceled".equals(status)) {
            //驳回后的执行逻辑 4:流程作废
            log.info("流程作废了");
            if (!promotionEntity.getStatus().equals(3))
                promotionEntity.setStatus(2);
            flowEntity.setStatus(4);
            flowService.updateByIdE(flowEntity);
            content = promotionEntity.getName() + "的晋升申请流程已作废，请重新发起";
        }

        //发送消息给晋升对象
        if (!StringUtils.isEmpty(content) && !j.equals(promotionEntity.getIsRemind())) {
            qwMsg.sendNoticeMsg("晋升", content, NoticeConst.MSG_TYPE_PROMOTION, true, promotionEntity.getOid(), flowEntity.getRelateId(), "晋升", promotionEntity.getCode(), null, null);
            if ("approved".equals(status)) {
                promotionEntity.setIsRemind(1);
            }
        }
        promotionDao.updateById(promotionEntity);
    }


    @Transactional
    public void updateAwardStatus(String type, String status, AwardApplicantEntity awardApplicantEntity, FlowEntity flowEntity, String url) {

        log.info("type==========>>{}", type);
        //        审核通过 type为：approveClose ,status为：approved
        if ("createResult".equals(type) && "success".equals(status)) {
            awardApplicantEntity.setBpmUrl(url);
            awardApplicantEntity.setApprovalStatus(1);
            awardApplicantEntity.setDistributionStatus(1);
        }
        if ("approveClose".equals(type) && "approved".equals(status)) {
            awardApplicantEntity.setApprovalStatus(2);
            awardApplicantEntity.setDistributionStatus(2);
            if (awardApplicantEntity.getPackageId() != null) {
                List<AwardApplicantEntity> awardApplicantEntityList = awardApplicantDao.selectList(new QueryWrapper<AwardApplicantEntity>().eq("package_id", awardApplicantEntity.getPackageId()).eq("distribution_status", 0).or().eq("distribution_status", 1));
                awardApplicantEntityList.remove(awardApplicantEntity);
                if (CollectionUtils.isEmpty(awardApplicantEntityList)) {
                    AwardPackageEntity awardPackageEntity = awardPackageDao.selectOne(new QueryWrapper<AwardPackageEntity>().eq("id", awardApplicantEntity.getPackageId()));
                    awardPackageEntity.setDistributionStatus(2);
                    awardPackageDao.updateById(awardPackageEntity);
                }
            }
            List<AwardInfoEntity> awardInfoEntityList = awardInfoDao.selectList(new QueryWrapper<AwardInfoEntity>().eq("distribution_id", awardApplicantEntity.getId()));
            List<Long> ids = new ArrayList<>();
            for (AwardInfoEntity entity : awardInfoEntityList) {
                ids.add(entity.getId());
            }
            flowEntity.setStatus(3);
            flowService.updateByIdE(flowEntity);
            //暂时注释
            neuEmployeeSalaryService.saveAwardApplicant(ids);
        }
        if ("approveClose".equals(type) && "canceled".equals(status)) {
            //驳回后的执行逻辑 4:流程作废
            log.info("流程作废了");
            awardApplicantEntity.setApprovalStatus(0);
            awardApplicantEntity.setDistributionStatus(0);
            flowEntity.setStatus(4);
            flowService.updateByIdE(flowEntity);
        }
        awardApplicantDao.updateById(awardApplicantEntity);
    }


    @Transactional
    public void updateAwardPackageStatus(String type, String status, AwardPackageEntity awardPackageEntity, FlowEntity flowEntity, String url) {

        log.info("type==========>>{}", type);
        //        审核通过 type为：approveClose ,status为：approved
        if ("createResult".equals(type) && "success".equals(status)) {
            awardPackageEntity.setBpmUrl(url);
            awardPackageEntity.setStatus(1);
        }
        if ("approveClose".equals(type) && "approved".equals(status)) {
            awardPackageEntity.setStatus(2);
            awardPackageEntity.setDistributionStatus(1);
            flowEntity.setStatus(3);
            flowService.updateByIdE(flowEntity);
        }
        if ("approveClose".equals(type) && "canceled".equals(status)) {
            //驳回后的执行逻辑 4:流程作废
            log.info("流程作废了");
            awardPackageEntity.setStatus(0);
            flowEntity.setStatus(4);
            flowService.updateByIdE(flowEntity);
        }
        awardPackageDao.updateById(awardPackageEntity);
    }

    @Transactional
    public void updateCertificateStatus(String type, String status, CertificateEntity CertificateEntity, FlowEntity flowEntity, String url, String s) throws Exception {

        log.info("type==========>>{}", type);
        //        审核通过 type为：approveClose ,status为：approved
        if ("createResult".equals(type) && "success".equals(status)) {
            if (!"2".equals(CertificateEntity.getStatus())) {
                CertificateEntity.setBpmUrl(url);
                CertificateEntity.setStatus("1");
                JSONArray jsonArray = JSONObject.parseObject(s).getJSONObject("data").getJSONObject("businessObject").getJSONArray("fields");
                int size = jsonArray.size();
                HashMap<String, String> map = new HashMap<>();
                for (int i = 0; i < size; i++) {
                    JSONObject jsonObject = jsonArray.getJSONObject(i);
                    String str = "";
                    if (!StringUtils.isEmpty(jsonObject.getString("value"))) {
                        str = jsonObject.getString("value").trim();
                    }
                    str = StringUtils.isEmpty(str) ? "0" : jsonObject.getString("value");
                    map.put(jsonObject.getString("id"), str);
                }
                CertificateEntity.setHrName(map.get("hrName"));
                CertificateEntity.setHrContract(map.get("hrContract"));
                CertificateEntity.setSalary(new BigDecimal(map.get("salary")));
                CertificateEntity.setWorkAddress(map.get("workAddress"));
            }
        }
        if ("approveClose".equals(type) && "approved".equals(status)) {
            CertificateEntity.setStatus("2");

            esignController.sendCertificate(CertificateEntity.getId().toString());
            flowEntity.setStatus(3);
            flowService.updateByIdE(flowEntity);
        }
        if ("approveClose".equals(type) && "canceled".equals(status)) {
            //驳回后的执行逻辑 4:流程作废
            log.info("流程作废了");
            CertificateEntity.setStatus("0");
            flowEntity.setStatus(4);
            flowService.updateByIdE(flowEntity);
        }
        certificateDao.updateById(CertificateEntity);
    }

    @Transactional
    public void updateCredentialStatus(String type, String status, CredentialHangEntity hangEntity, String url, String s, FlowEntity flowEntity) throws Exception {
        CredentialInfoEntity infoEntity = credentialInfoService.getByIdE(hangEntity.getCredentialId());
        log.info("type==========>>{}", type);
        //        审核通过 type为：approveClose ,status为：approved
        if ("createResult".equals(type) && "success".equals(status)) {
            if (!hangEntity.getStatus().equals(CredentialConst.HANG_STATUS_CHECKED)) {
                hangEntity.setBpmUrl(url);
                hangEntity.setCreateTime(new Date());
                hangEntity.setStatus(CredentialConst.HANG_STAUTS_CHECKING);
                infoEntity.setHangStatus(CredentialConst.HANG_STAUTS_CHECKING);
            }
        }
        if ("approveClose".equals(type) && "approved".equals(status)) {
            JSONArray jsonArray = JSONObject.parseObject(s).getJSONObject("data").getJSONObject("businessObject").getJSONArray("fields");
            int size = jsonArray.size();
            HashMap<String, Object> map = new HashMap<>();
            for (int i = 0; i < size; i++) {
                JSONObject jsonObject = jsonArray.getJSONObject(i);
                map.put(jsonObject.getString("id"), jsonObject.get("value"));
            }
            if (!ObjectUtils.isEmpty(map.get("allowance"))) {
                hangEntity.setAllowance(new BigDecimal(map.get("allowance").toString()));
            }
            if (!ObjectUtils.isEmpty(map.get("allowanceTime"))) {
                Date date = DateUtils.stringToDate(map.get("allowanceTime").toString(), "yyyy-MM-dd");
                hangEntity.setAllowanceTime(date);
            }
            hangEntity.setStatus(CredentialConst.HANG_STATUS_CHECKED);
            infoEntity.setHangStatus(CredentialConst.HANG_STATUS_CHECKED);
            flowEntity.setStatus(3);
            flowService.updateByIdE(flowEntity);
        }
        if ("approveClose".equals(type) && "canceled".equals(status)) {
            //驳回后的执行逻辑 4:流程作废
            log.info("流程作废了");
            if (!hangEntity.getStatus().equals(CredentialConst.HANG_STATUS_CHECKED)) {
                hangEntity.setStatus(CredentialConst.HANG_STATUS_APPLYE);
                infoEntity.setHangStatus(CredentialConst.HANG_STATUS_APPLYE);
                flowEntity.setStatus(4);
                flowService.updateByIdE(flowEntity);
            }

        }
        credentialInfoService.updateByIdE(infoEntity);
        credentialHangService.updateByIdE(hangEntity);
    }

    @Transactional
    public void updateDistributeLeaveStatus(String type, String status, DistributeLeaveEntity entity, String url, String s, FlowEntity flowEntity) throws Exception {
        log.info("type==========>>{}", type);
        //        审核通过 type为：approveClose ,status为：approved
        if ("createResult".equals(type) && "success".equals(status)) {
            if (!entity.getStatus().equals(LeaveConst.LEAVE_STATUS_CHECKED)) {
                entity.setCheckUrl(url);
                entity.setStatus(LeaveConst.LEAVE_STATUS_CHECKED);
            }
        }
        if ("approveClose".equals(type) && "approved".equals(status)) {
            entity.setStatus(LeaveConst.LEAVE_STATUS_CHECKED);
            flowEntity.setStatus(3);
            flowService.updateByIdE(flowEntity);
        }
        if ("approveClose".equals(type) && "canceled".equals(status)) {
            //驳回后的执行逻辑 4:流程作废
            log.info("流程作废了");
            if (!entity.getStatus().equals(LeaveConst.LEAVE_STATUS_CHECKED)) {
                entity.setStatus(LeaveConst.LEAVE_STATUS_APPLY);
                flowEntity.setStatus(4);
                flowService.updateByIdE(flowEntity);
            }

        }
        distributeLeaveService.updateByIdE(entity);
    }

    /**
     * 请假调休流程
     *
     * @param type
     * @param status
     * @param leaveInfoEntity
     */
    @Transactional
    public void updateLeaveStatus(String type, String status, LeaveInfoEntity leaveInfoEntity, FlowEntity flowEntity, String url, String mobileUrl) {
        String content = "";
        EmployeeInfoEntity employeeInfoEntity = employeeInfoService.getByIdE(leaveInfoEntity.getOid());
        Integer j = 1;
        if ("createResult".equals(type) && "success".equals(status)) {
            leaveInfoEntity.setCheckUrl(url);
            leaveInfoEntity.setMobileUrl(mobileUrl);
            if (leaveInfoEntity.getDealStatus() == 0) {
                leaveInfoEntity.setDealStatus(1);
                // TODO: 2020/12/2 调用ehr接口预减除年假
                doNeusfotLeave(leaveInfoEntity, "1");
            }

            leaveInfoService.updateByIdE(leaveInfoEntity);

        }

        log.info("员工请假调休流程：type:{},status:{}", type, status);
        if ("approveClose".equals(type) && "approved".equals(status)) {
            //审核通过则修改订单状态IsVerify为2
            if (!ObjectUtils.isEmpty(leaveInfoEntity)) {
                log.info("请假调休审核通过，修改状态为2");
                leaveInfoEntity.setDealStatus(2);
                leaveInfoService.updateByIdE(leaveInfoEntity);
                flowEntity.setStatus(3);
                flowService.updateByIdE(flowEntity);
                content = employeeInfoEntity.getName() + "的请假调休请流程已审批已经通过";
                // TODO: 2020/12/2 调用ehr接口确认减除年假
                doNeusfotLeave(leaveInfoEntity, "2");
//                //审核通过发送入职待办
//                employessController.sendHireToDo(employeeInfoEntity);
//                //更新录用待办通知为已处理状态
//                noticeController.updateNoticeTodo(employeeInfoEntity.getOid(), NoticeConst.TODO_TYPE_HIRE);

            }
        }
        if ("approveClose".equals(type) && "canceled".equals(status)) {
            //驳回后的执行逻辑 4:流程作废
            log.info("流程作废了");
            //如果是未处理状态作废将该条信息置为未发起
            if (!leaveInfoEntity.getDealStatus().equals(2)) {
                leaveInfoEntity.setDealStatus(0);
                leaveInfoService.updateByIdE(leaveInfoEntity);
                // TODO: 2020/12/2 调用ehr接添加回预扣除年假
                doNeusfotLeave(leaveInfoEntity, "3");
            }
            flowEntity.setStatus(4);
            flowService.updateByIdE(flowEntity);
            content = employeeInfoEntity.getName() + "的请假调休申请流程审批已作废，请重新发起";
        }


        if (!StringUtils.isEmpty(content) && "approveClose".equals(type)) {
            qwMsg.sendNoticeMsg("请假调休", content, NoticeConst.MSG_TYPE_LEAVE, true, employeeInfoEntity.getOid(), flowEntity.getRelateId(), "请假调休", employeeInfoEntity.getCode(), null, null);
        }

    }


    /**
     * 新员工转正流程
     *
     * @param type
     * @param status
     * @param
     */
    @Transactional
    public void newEmployeeRegular(String type, String status, FlowEntity flowEntity, String url, JSONObject jsonObject, String s) {
        String content = "";
        Long oid = flowEntity.getOid();
        EmployeeInfoEntity employeeInfoEntity = employeeInfoService.getByIdE(oid);
        EmployeeBpmEntity bpmEntity = employeeBpmService.getByIdE(oid);
        if (ObjectUtils.isEmpty(bpmEntity)) {
            bpmEntity = BeanUtilsMabach.doToDto(employeeInfoEntity, EmployeeBpmEntity.class);
            employeeBpmService.saveE(bpmEntity);
        }
        Long relateId = flowEntity.getRelateId();
        String mobile = employeeInfoEntity.getMobile();
        String code = employeeInfoEntity.getCode();
//        RegularBpmEntity regularBpmEntity = regularBpmService.getByIdE(relateId);

        Integer j = 1;

        //        审核通过 type为：approveClose ,status为：approved
        log.info("员工转正流程：type:{},status:{}", type, status);
        if ("createResult".equals(type) && "success".equals(status)) {


            employeeInfoEntity.setRegularIsDone(1); //默认为空，0:转正未处理，1：已处理
//            employeeInfoEntity.setIsRegular(0); //是否转正0:未转正，1：转正 ，2：延期转正 3：不予转正
            employeeInfoEntity.setRegularBpmStatus(1);//0:待发起 ，1：已发起待审批，2：审批完成，3：作废
            employeeInfoEntity.setRegularCheckUrl(url); //审核详情链接
            employeeInfoService.updateByIdE(employeeInfoEntity);

            //修改招聘数据
            if(!org.springframework.util.StringUtils.isEmpty(employeeInfoEntity.getRecruitmentId())){
                EmployeeRecruitmentEntity employeeRecruitmentEntity =new EmployeeRecruitmentEntity();
                employeeRecruitmentEntity.setId(employeeInfoEntity.getRecruitmentId());
                employeeRecruitmentEntity.setRegularIsDone(1); //默认为空，0:转正未处理，1：已处理
//            employeeInfoEntity.setIsRegular(0); //是否转正0:未转正，1：转正 ，2：延期转正 3：不予转正
                employeeRecruitmentEntity.setRegularBpmStatus(1);//0:待发起 ，1：已发起待审批，2：审批完成，3：作废
                employeeRecruitmentEntity.setRegularCheckUrl(url); //审核详情链接
                employeeRecruitmentService.updateByIdE(employeeRecruitmentEntity);
            }

            //更新录用待办通知为已处理状态

        }


        //审核通过则修改状态
        if ("approveClose".equals(type) && "approved".equals(status)) {
            //审核通过则修改状态IsVerify为3
            EmployeeBpmEntity employeeBpmEntity = employeeBpmService.getByIdE(oid);
            if (ObjectUtils.isEmpty(employeeBpmEntity)) {
                employeeBpmEntity = BeanUtilsMabach.doToDto(employeeInfoEntity, EmployeeBpmEntity.class);
                employeeBpmService.saveE(employeeBpmEntity);
            }
            employeeInfoEntity.setRegularIsDone(1); //默认为空，0:转正未处理，1：已处理
            Integer isRegular = employeeInfoEntity.getIsRegular();
            if (isRegular.equals(0)) {
                employeeInfoEntity.setIsRegular(1);//转正操作 0:未转正，1：转正 ，2：延期转正 3：不予转正，4：提前转正
            }
            employeeInfoEntity.setRegularBpmStatus(2); //0:待发起 ，1：已发起待审批，2：审批完成，3：作废
            flowEntity.setStatus(3);
            flowService.updateByIdE(flowEntity);
            content = employeeInfoEntity.getName() + "：您的转正申请流程已审批已经通过";
            JSONObject obj = JSON.parseObject(s, JSONObject.class);
            JSONObject data = obj.getJSONObject("data");
            JSONObject businessObject = data.getJSONObject("businessObject");
            JSONArray fields = businessObject.getJSONArray("fields");
//            JSONArray fields = jsonObject.getJSONArray("fields");
            String replyscore = "";  //答辩综合分数
            String send = ""; //360考评得分人数发送
            String receive = ""; //360考评得分人数接收
            String score = ""; //360评分
            String joblevelname = ""; //职级
            BigDecimal salary = null; //月薪固定
            BigDecimal modulesalary = null; //模块/绩效
            for (Object field : fields) {
                JSONObject object = JSON.parseObject(field.toString(), JSONObject.class);
                String id = object.getString("id");

//                答辩综合分数
                if ("replyscore".equals(id)) {
                    String value = object.getString("value");
                    if (!StringUtils.isEmpty(value)) {
                        replyscore = value;
                    }
                }
//                360考评得分人数发送
                if ("send".equals(id)) {
                    String value = object.getString("value");
                    if (!StringUtils.isEmpty(value)) {
                        send = value;
                    }
                }
//                360考评得分人数接收
                if ("receive".equals(id)) {
                    String value = object.getString("value");
                    if (!StringUtils.isEmpty(value)) {
                        receive = value;
                    }
                }
//                360评分
                if ("score".equals(id)) {
                    String value = object.getString("value");
                    if (!StringUtils.isEmpty(value)) {
                        score = value;
                    }
                }
//                职级
                if ("joblevelname".equals(id)) {
                    String value = object.getString("value");
                    if (!StringUtils.isEmpty(value)) {
                        joblevelname = value;
                    }
                }
//                月薪固定
                if ("salary".equals(id)) {

                    String v = object.getString("value");

                    if (!StringUtils.isEmpty(v)) {
                        BigDecimal value = new BigDecimal(v);
                        salary = value;
                    } else {
                        salary = new BigDecimal(0);
                    }
                }
//                模块/绩效
                if ("modulesalary".equals(id)) {

                    String v = object.getString("value");

                    if (!StringUtils.isEmpty(v)) {
                        BigDecimal value = new BigDecimal(v);
                        modulesalary = value;
                    } else {
                        modulesalary = new BigDecimal(0);
                    }
                }


            }
            //                回填信息
            employeeInfoEntity.setReplyScore(replyscore);
            employeeInfoEntity.setSend(send);
            employeeInfoEntity.setReceive(receive);
            employeeInfoEntity.setScore(score);

            employeeBpmEntity.setReplyScore(replyscore);
            employeeBpmEntity.setSend(send);
            employeeBpmEntity.setReceive(receive);
            employeeBpmEntity.setScore(score);

            if (!StringUtils.isEmpty(joblevelname)) {
                Long aLong = jobController.jobLevel.get(joblevelname);
                if (aLong != null) {
                    employeeInfoEntity.setJobLevelId(aLong);
                    employeeBpmEntity.setJobLevelId(aLong);
                }

            }
//                更新工资 只有大于0才更新
            int i = salary.compareTo(new BigDecimal(0));
            int i1 = modulesalary.compareTo(new BigDecimal(0));
            BigDecimal add = salary.add(modulesalary);
            int i2 = add.compareTo(new BigDecimal(0));


            if (i > 0) {
                employeeInfoEntity.setBasicSalary(salary);
                employeeBpmEntity.setBasicSalary(salary);
            }
            if (i1 > 0) {
                employeeInfoEntity.setPerformance(modulesalary);
                employeeBpmEntity.setPerformance(modulesalary);
            }
            if (i2 > 0) {
                employeeInfoEntity.setMonthlySalary(add);
                employeeBpmEntity.setMonthlySalary(add);
            }


            employeeBpmService.updateByIdE(employeeBpmEntity);
            neusoftEmployeeChangeService.uploadRegularChange(null, employeeBpmEntity, employeeInfoEntity, salary, modulesalary);
//            regularBpmService.updateByIdE(regularBpmEntity);
            employeeInfoDao.updateById(employeeInfoEntity);

            //修改招聘数据
            if(!org.springframework.util.StringUtils.isEmpty(employeeInfoEntity.getRecruitmentId())){
                EmployeeRecruitmentEntity employeeRecruitmentEntity =new EmployeeRecruitmentEntity();
                employeeRecruitmentEntity.setId(employeeInfoEntity.getRecruitmentId());
                employeeRecruitmentEntity.setRegularIsDone(1); //默认为空，0:转正未处理，1：已处理
                employeeRecruitmentEntity.setJobLevelId(employeeInfoEntity.getJobLevelId());
                employeeRecruitmentEntity.setIsRegular(1);//转正操作 0:未转正，1：转正 ，2：延期转正 3：不予转正，4：提前转正
                employeeRecruitmentEntity.setRegularBpmStatus(2); //0:待发起 ，1：已发起待审批，2：审批完成，3：作废
                employeeRecruitmentEntity.setBasicSalary(employeeInfoEntity.getBasicSalary());
                employeeRecruitmentEntity.setPerformance(employeeInfoEntity.getPerformance());
                employeeRecruitmentEntity.setMonthlySalary(employeeInfoEntity.getMonthlySalary());
                employeeRecruitmentService.updateByIdE(employeeRecruitmentEntity);
            }

            //薪资变动

            asyncMethod.saveSalaryChange(s, flowEntity, null, employeeInfoEntity.getRegularCheckUrl());

            //将待转正待办设置为完成
            noticeController.updateNoticeTodo(employeeInfoEntity.getOid(), NoticeConst.TODO_TYPE_REGULAR);

            //企微推送审核
            List<QwUserEntity> qwUserEntitys = qwUserDao.selectList(new QueryWrapper<QwUserEntity>().eq("mobile", mobile).or().eq("user_code", code));
            if (!CollectionUtils.isEmpty(qwUserEntitys)) {
                QwUserEntity qwUserEntity = qwUserEntitys.get(0);
                String userid = qwUserEntity.getUserid();
                try {
                    qwMsg.sendNoticeMsg(content, userid);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }


        }


        if ("approveClose".equals(type) && "canceled".equals(status)) {
            //驳回后的执行逻辑 4:流程作废
            log.info("流程作废了");
            //作废将该条信息置为未发起
            employeeInfoEntity.setRegularBpmStatus(0);
            employeeInfoEntity.setRegularIsDone(0);
            employeeInfoService.updateByIdE(employeeInfoEntity);

            //修改招聘数据
            if(!org.springframework.util.StringUtils.isEmpty(employeeInfoEntity.getRecruitmentId())){
                EmployeeRecruitmentEntity employeeRecruitmentEntity =new EmployeeRecruitmentEntity();
                employeeRecruitmentEntity.setId(employeeInfoEntity.getRecruitmentId());
                employeeRecruitmentEntity.setRegularBpmStatus(0);
                employeeRecruitmentEntity.setRegularIsDone(0);
                employeeRecruitmentService.updateByIdE(employeeRecruitmentEntity);
            }

            flowEntity.setStatus(4);
            flowService.updateByIdE(flowEntity);

        }


    }


    /**
     * 管理转正流程
     *
     * @param type
     * @param status
     * @param
     */
    @Transactional
    public void ManagementRegular(String type, String status, FlowEntity flowEntity, String url, String s) {

        Long promotionId = flowEntity.getRelateId();
        RegularBpmEntity regularBpmEntity = regularBpmDao.selectOne(new QueryWrapper<RegularBpmEntity>().eq("id", promotionId).eq("is_delete", 0));
        Long oid = regularBpmEntity.getOid();
        EmployeeInfoEntity employeeInfoEntity = employeeInfoService.getByIdE(oid);
        String code = employeeInfoEntity.getCode();
        String mobile = employeeInfoEntity.getMobile();
        EmployeeBpmEntity employeeBpmEntity = employeeBpmService.getByIdE(oid);
        if (ObjectUtils.isEmpty(employeeBpmEntity)) {
            employeeBpmEntity = BeanUtilsMabach.doToDto(employeeInfoEntity, EmployeeBpmEntity.class);
            employeeBpmService.saveE(employeeBpmEntity);
        }


        //        审核通过 type为：approveClose ,status为：approved
        log.info("员工转正流程：type:{},status:{}", type, status);
        if ("createResult".equals(type) && "success".equals(status)) {
            regularBpmEntity.setCheckUrl(url);
            if (!regularBpmEntity.getRegularBpmStatus().equals(3))
                regularBpmEntity.setRegularBpmStatus(2); //2: 已发起待审批
            regularBpmService.updateByIdE(regularBpmEntity);
        }


        if ("approveClose".equals(type) && "approved".equals(status)) {
            //审核通过则修改状态IsVerify为3

            log.info("录用审核通过，修改状态为3");

            flowEntity.setStatus(3);
            flowService.updateByIdE(flowEntity);
            String content = regularBpmEntity.getName() + "：您的转正申请流程已审批已经通过";
            JSONObject obj = JSON.parseObject(s, JSONObject.class);
            JSONObject data = obj.getJSONObject("data");
            JSONObject businessObject = data.getJSONObject("businessObject");
            JSONArray fields = businessObject.getJSONArray("fields");
            String replyscore = "";  //答辩综合分数
            String send = ""; //360考评得分人数发送
            String receive = ""; //360考评得分人数接收
            String score = ""; //360评分
            String joblevelname = ""; //职级
            BigDecimal salary = null; //月薪固定
            BigDecimal modulesalary = null; //模块/绩效
            for (Object field : fields) {
                JSONObject object = JSON.parseObject(field.toString(), JSONObject.class);
                String id = object.getString("id");
//                答辩综合分数
                if ("replyscore".equals(id)) {
                    String value = object.getString("value");
                    if (!StringUtils.isEmpty(value)) {
                        replyscore = value;
                    }
                }
//                360考评得分人数发送
                if ("send".equals(id)) {
                    String value = object.getString("value");
                    if (!StringUtils.isEmpty(value)) {
                        send = value;
                    }
                }
//                360考评得分人数接收
                if ("receive".equals(id)) {
                    String value = object.getString("value");
                    if (!StringUtils.isEmpty(value)) {
                        receive = value;
                    }
                }
//                360评分
                if ("score".equals(id)) {
                    String value = object.getString("value");
                    if (!StringUtils.isEmpty(value)) {
                        score = value;
                    }
                }
//                职级
                if ("joblevelname".equals(id)) {
                    String value = object.getString("value");
                    if (!StringUtils.isEmpty(value)) {
                        joblevelname = value;
                    }
                }
//                月薪固定
                if ("salary".equals(id)) {

                    String v = object.getString("value");

                    if (!StringUtils.isEmpty(v)) {
                        BigDecimal value = new BigDecimal(v);
                        salary = value;
                    } else {
                        salary = new BigDecimal(0);
                    }
                }
//                模块/绩效
                if ("modulesalary".equals(id)) {
                    String v = object.getString("value");

                    if (!StringUtils.isEmpty(v)) {
                        BigDecimal value = new BigDecimal(v);
                        modulesalary = value;
                    } else {
                        modulesalary = new BigDecimal(0);
                    }
                }
//
            }
            //                更新评分
            regularBpmEntity.setReplyScore(replyscore);
            regularBpmEntity.setSend(send);
            regularBpmEntity.setReceive(receive);
            regularBpmEntity.setScore(score);
            if (!StringUtils.isEmpty(joblevelname)) {
                Long aLong = jobController.jobLevel.get(joblevelname);
                if (aLong != null) {
                    employeeInfoEntity.setJobLevelId(aLong);
                    employeeBpmEntity.setJobLevelId(aLong);
                    regularBpmEntity.setJobLevelId(aLong);
                }

            }
            //更新工资 只有大于0才更新
            int i = salary.compareTo(new BigDecimal(0));
            int k = modulesalary.compareTo(new BigDecimal(0));
            BigDecimal add = salary.add(modulesalary);
            int j = add.compareTo(new BigDecimal(0));
            if (i > 0) {
                employeeInfoEntity.setBasicSalary(salary);
                employeeBpmEntity.setBasicSalary(salary);
                regularBpmEntity.setBasicSalary(salary);
            }
            if (k > 0) {
                employeeInfoEntity.setPerformance(modulesalary);
                employeeBpmEntity.setPerformance(modulesalary);
                regularBpmEntity.setPerformance(modulesalary);
            }
            if (j > 0) {
                employeeInfoEntity.setMonthlySalary(add);
                employeeBpmEntity.setMonthlySalary(add);
                regularBpmEntity.setMonthlySalary(add);
            }


            Integer isRegular = regularBpmEntity.getIsRegular();
            if (ObjectUtils.isEmpty(isRegular) || isRegular.equals(0)) {
                regularBpmEntity.setIsRegular(1);
            }
            regularBpmEntity.setRegularBpmStatus(3); //设置为审批完成
            employeeBpmService.updateByIdE(employeeBpmEntity);
            regularBpmService.updateByIdE(regularBpmEntity);
            //管理晋升转正后调用转正异动接口
            neusoftEmployeeChangeService.uploadRegularChange(regularBpmEntity, null, null, salary, modulesalary);
            employeeInfoDao.updateById(employeeInfoEntity);
            qwMsg.sendNoticeMsg("晋升转正", content, NoticeConst.MSG_TYPE_PROMOTION_REGULAR, true, employeeInfoEntity.getOid(), regularBpmEntity.getId(), "晋升转正", employeeInfoEntity.getCode(), null, null);
            //将待转正待办设置为完成
            noticeController.updateNoticeTodo(regularBpmEntity.getId(), NoticeConst.MSG_TYPE_PROMOTION_REGULAR);
            //薪资变动
            asyncMethod.saveSalaryChange(s, flowEntity, null, regularBpmEntity.getCheckUrl());

        }


//驳回后的执行逻辑 4:流程作废
        if ("approveClose".equals(type) && "canceled".equals(status)) {

            log.info("流程作废了");
            //作废将该条信息置为未发起
            if (!regularBpmEntity.getRegularBpmStatus().equals(3))
                regularBpmEntity.setRegularBpmStatus(0);
            regularBpmService.updateByIdE(regularBpmEntity);
            flowEntity.setStatus(4);
            flowService.updateByIdE(flowEntity);

        }


    }

    private void doNeusfotLeave(LeaveInfoEntity entity, String type) {

    }


}
